<template>
  <view class="page">
    <!-- 状态栏占位 -->
    <view :style="{ height: statusBarHeight + 'px' }"></view>

    <!-- 导航栏 -->
    <view class="nav-bar">
      <view class="nav-left" @tap="goBack">
        <text class="fa fa-chevron-left fa-gray"></text>
      </view>
      <view class="nav-title">讨论区</view>
      <view class="nav-right" @tap="goToMessages">
        <text class="fa fa-bell-o search-icon fa-gray"></text>
      </view>
    </view>

    <!-- 主内容 -->
    <scroll-view scroll-y class="content">
      <!-- 发帖输入框 -->
      <view class="create-post">
        <image
          class="avatar"
          src="https://images.unsplash.com/photo-1544005313-94ddf0286df2?q=80&w=600&auto=format&fit=crop"
          mode="aspectFill"
        />
        <view class="input-placeholder-wrapper">
          <text class="input-placeholder">发起问题/讨论...</text>
        </view>
        <view class="publish-btn" @tap="handlePublish">
          <text class="publish-btn-text">发布</text>
        </view>
      </view>

      <!-- 帖子列表 -->
      <view class="posts-list">
        <!-- 帖子1 -->
        <view class="post-card">
          <view class="post-header">
            <image
              class="post-avatar"
              src="https://images.unsplash.com/photo-1500648767791-00dcc994a43e?q=80&w=600&auto=format&fit=crop"
              mode="aspectFill"
            />
            <view class="post-user-info">
              <text class="post-author">王健 · 讲师</text>
              <text class="post-time">15 分钟前</text>
            </view>
          </view>
          <text class="post-content"
            >关于重症患者液体管理，有哪些关键的观察指标？欢迎讨论。</text
          >
          <view class="post-actions">
            <view class="action-btn" @tap="handleLike(0)">
              <text class="fa fa-thumbs-o-up fa-gray"></text>
              <text class="action-text">36</text>
            </view>
            <view class="action-btn" @tap="handleComment(0)">
              <text class="fa fa-comment-o fa-gray"></text>
              <text class="action-text">12</text>
            </view>
            <view class="action-btn" @tap="handleBookmark(0)">
              <text class="fa fa-bookmark-o fa-gray"></text>
              <text class="action-text">收藏</text>
            </view>
          </view>
        </view>

        <!-- 帖子2 -->
        <view class="post-card">
          <view class="post-header">
            <image
              class="post-avatar"
              src="https://images.unsplash.com/photo-1527980965255-d3b416303d12?q=80&w=600&auto=format&fit=crop"
              mode="aspectFill"
            />
            <view class="post-user-info">
              <text class="post-author">赵青 · 护士长</text>
              <text class="post-time">1 小时前</text>
            </view>
          </view>
          <text class="post-content"
            >护理质量例会本周要汇报的指标模板，有没有推荐？</text
          >
          <view class="post-actions">
            <view class="action-btn" @tap="handleLike(1)">
              <text class="fa fa-thumbs-o-up fa-gray"></text>
              <text class="action-text">18</text>
            </view>
            <view class="action-btn" @tap="handleComment(1)">
              <text class="fa fa-comment-o fa-gray"></text>
              <text class="action-text">6</text>
            </view>
            <view class="action-btn" @tap="handleBookmark(1)">
              <text class="fa fa-bookmark-o fa-gray"></text>
              <text class="action-text">收藏</text>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
    };
  },
  onLoad() {
    // 获取系统状态栏高度
    const systemInfo = uni.getSystemInfoSync();
    this.statusBarHeight = systemInfo.statusBarHeight || 0;
  },
  methods: {
    // 导航方法
    goToHome() {
      uni.navigateTo({
        url: "/pages/home/home",
      });
    },
    goToProfile() {
      uni.navigateTo({
        url: "/pages/profile/profile",
      });
    },
    goToMessages() {
      uni.navigateTo({
        url: "/pages/message/message",
      });
    },

    // 发布帖子
    handlePublish() {
      uni.showToast({
        title: "发布功能开发中",
        icon: "none",
      });
    },

    // 点赞
    handleLike(index) {
      uni.showToast({
        title: "点赞成功",
        icon: "success",
      });
    },

    // 评论
    handleComment(index) {
      uni.showToast({
        title: "评论功能开发中",
        icon: "none",
      });
    },

    // 收藏
    handleBookmark(index) {
      uni.showToast({
        title: "收藏成功",
        icon: "success",
      });
    },
  },
};
</script>

<style scoped>
.page {
  min-height: 100vh;
  background-color: #ffffff;
  display: flex;
  flex-direction: column;
}

/* 导航栏 */
.nav-bar {
  height: 44px;
  background-color: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-left {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  color: #000000;
}

.nav-right {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.icon {
  font-size: 20px;
}

/* 主内容 */
.content {
  flex: 1;
  padding: 0 16px 70px;
  box-sizing: border-box;
}

/* 发帖输入框 */
.create-post {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.input-placeholder-wrapper {
  flex: 1;
  background-color: #f3f4f6;
  border-radius: 12px;
  padding: 0px 12px;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.input-placeholder {
  font-size: 14px;
  color: #9ca3af;
}

.publish-btn {
  background-color: #2563eb;
  border-radius: 8px;
  padding: 0px 12px;
  min-height: 36px;
  line-height: 36px;
}

.publish-btn-text {
  font-size: 14px;
  color: #ffffff;
  font-weight: 500;
}

/* 帖子列表 */
.posts-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.post-card {
  background-color: #f9fafb;
  border-radius: 16px;
  padding: 16px;
}

.post-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.post-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}

.post-user-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.post-author {
  font-size: 14px;
  font-weight: 500;
  color: #111827;
}

.post-time {
  font-size: 12px;
  color: #6b7280;
}

.post-content {
  font-size: 14px;
  color: #374151;
  line-height: 1.6;
  margin-bottom: 12px;
}

/* 帖子操作按钮 */
.post-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
}

.action-icon {
  font-size: 16px;
}

.action-text {
  font-size: 12px;
  color: #6b7280;
}

/* 底部导航栏 */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid #f3f4f6;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.tabbar-icon {
  font-size: 22px;
}

.tabbar-text {
  font-size: 12px;
  color: #6b7280;
}

.tabbar-text-active {
  color: #2563eb;
  font-weight: 500;
}

.tabbar-item-active {
  color: #2563eb;
}
</style>
